//index.js  777777711
var common = require("../../utils/public.js") //引入public.js脚本
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
var api = require('../../utils/api.js')
var time = require("../../utils/time.js");
var { strDiscode} = require("../../utils/wxParse/wxDiscode.js");
const { async } = require("../../utils/runtime/runtime.js");
var qqmapsdk;
//获取应用实例
const app = getApp()
let off = true
Page({
  data: {
    toPage:[],
    getDefault:[],
    loginCode:false,
    loginCode1:false,
    // 数据是否加载完
    noMore: false,
    // 加载中
    loading: false,
    cityId:'',
    totalPage:1,//底部商品列表页总页数
    currents:1,//当前商品页数
    size: 10,//初始渲染条数
    current: 1,
    province: '',
    city: '',
    latitude: '',
    longitude: '',
    // 未登录时
    login: '',
    vipId:0,
    // 
    inputShowed: false,
    inputVal: "",
    // 轮播
    imgUrls: [],
    current: 0,
    // 公告内容
    noticeList: [],
    //专区
    spec:[],
    // 商品分类start
    firstList: [],
    secondList: [],
    navigate_type: '', //分类类型，是否包含二级分类
    slideWidth: '', //滑块宽
    slideLeft: 0, //滑块位置
    totalLength: '', //当前滚动列表总长
    slideShow: false,
    showBegin:false,
    slideRatio: '',
    // 商品分类end
    // 人气爆款单(品牌推广区)固定3款产品
    fixed_list: [],
    // 限时抢购
    limited_list: [],
    hour:'',
    minute:'',
    second:'',
    // 底部商品列表数据
    type_id: '',
    // 底部商品导航
    nav_list: [{
      id: '',
      name: '猜你喜欢',
      remarks: '最懂你'
    }],
    // 底部商品数组
    proList: [],
    rookieGoods:[],
    vipGoods:[],
    onOff: true,
  },
  getTo:function(e){
    this.setData({
      proList: e.detail.list
    })
  },
  
  // 跳转商品详情
  todetail: common.throttleFunc(function (e) {
    let types = e.currentTarget.dataset.types 
    if (wx.getStorageSync("type")== -1){
      wx.showToast({
        title: '请您先进行身份选择',
        icon: 'none',
        duration: 1500
      })
      wx.navigateTo({
        url: '/pages/sf_xz/sf_xz',
      })
    } else if (wx.getStorageSync("type") == 1){
      if (wx.getStorageSync('codeNum') == 103) {
        //未注册商铺 跳转商铺注册页
        wx.showToast({
          title: '您还未注册店铺！',
          icon: 'none',
          duration: 1500
        })

        wx.navigateTo({
          url: '/pages/type/type',
        })


      } else if (wx.getStorageSync('codeNum') == 104) {
        //商铺审核中 
        wx.showToast({
          title: '您的商铺审核中！',
          icon: 'none',
          duration: 1000
        })
        wx.navigateTo({
          url: '/pages/shopBack/shopBack?type=' + 1,
        })
      }
      else if (wx.getStorageSync('codeNum') == 105) {
        //商铺审核未通过
        wx.showToast({
          title: '您申请的店铺暂未审核通过！',
          icon: 'none',
          duration: 1000
        })

        wx.navigateTo({
          url: '/pages/type/type',
        })


      }
      else if (wx.getStorageSync('codeNum') == 99) {

        //登录跳转商品详情界面
        wx.navigateTo({
          url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id + '&types=' + types ,
        })
      } 
      
    } else if (wx.getStorageSync("type") == 2){
      if (wx.getStorageSync('codeNum') != 99) {
        wx.showToast({
          title: '请您先注册一个收货地址',
          icon: 'none',
          duration: 1500
        })
        wx.navigateTo({
          url: '/pages/edit-address/edit-address',
        })
      } else {
        //登录跳转商品详情界面
        wx.navigateTo({
          url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id + '&types=' + types ,
        })
      }
     
    } else if (wx.getStorageSync('codeNum') == 99) {

      //登录跳转商品详情界面
      wx.navigateTo({
        url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id + '&types=' + types,
      })
    } else {
      wx.navigateTo({
        url: '/pages/userMess/userMess',
      })
    }
  }),
  //跳转公告详情页
  forNotice: function (e) {
    wx.navigateTo({
      url: '/pages/noticeList/noticeList?id=' + e.currentTarget.dataset.id,
    })
  },
  //跳转活动详情 1 秒杀 2 新人 3 vip
  moreGoods(e){
    wx.navigateTo({
      url: '/pages/activity/activity?type=' + e.currentTarget.dataset.type + '&vipFlag=' + wx.getStorageSync("vipFlag"),
    })
  },
  // 搜索栏
  showInput: function() {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function() {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function() {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function(e) {
    this.setData({
      inputVal: e.detail.value
    });
  },
  // 自定义轮播indicator-dots样式
  swiperChange: function(e) {
    var that = this;
    if (e.detail.source == 'touch' || e.detail.source == 'autoplay') {
      that.setData({
        current: e.detail.current
      })
    }
  },
 
  // 滚动公告截获竖向滑动
  catchTouchMove: function(res) {
    return false
  },


  onLoad:async function(options) {
      let that = this 
      this.setData({
        type : wx.getStorageSync('type')
      })
    //判断options
    if (JSON.stringify(options) == '{}') {
      that.city()
      that.getUserLocation();
    } else {
      that.setData({
        city: options.city
      })
    }
    that.getGoodsList();
    that.getAll()
    //计算屏幕宽度
    var systemInfo = wx.getSystemInfoSync();
    that.setData({
      windowWidth: systemInfo.windowWidth,
    })
    //计算比例
  
    // 获取index_tab高度
    var query = wx.createSelectorQuery();
    query.select('.index_tab').boundingClientRect(function(rect) {
      that.setData({
        height: rect.height + 'px'
      })
    }).exec();
    
  },
  // 首页打电话
  callGetPhone: function () {
    wx.navigateTo({
      url: '/pages/kefu/kefu',
    })
  },
  //首页各种专区、活动
  getIndexSpc(){
    let that=this
    let firstList = []
    let secondList = []
    let getDefault = []
    let toPage = []
    //类型 首页icon
    api.toExample({
      cityId: wx.getStorageSync("cityId"),
    }).then(res=>{
      if (res.result){
        var arr = res.object
        var zindex = res.object.length / 2
        res.object.forEach(function(v,index){
          if (index<zindex){
            firstList.push(v)
          }else{
            secondList.push(v)
          }
        })
        that.setData({
          firstList,
          secondList,
          arr: arr
        })
        that.getRatio();
      }
      
    })
    //首页专场
    api.toPerformances({
      cityId: wx.getStorageSync("cityId"),
      userId: wx.getStorageSync("openId"),
    }).then(res => {
      if (res.result) {
        res.object.forEach(function(v){
          if (v.orders>0){
            getDefault.push(v)
          }else{
            toPage.push(v)
          }
          
        })
        if(wx.getStorageSync('type') == "2"){
          getDefault.forEach(v=>{
            v.goodsInfos.forEach(j=>{
              api.roleSwitch(j.goodsDetailsEntityList[0])
            })
          })
        }
        that.setData({
          getDefault,
          toPage

        })
      }
    })
    //首页专区
    api.toSpe({
      cityId: wx.getStorageSync("cityId"),
    }).then(res => {
      if (res.result && res.object.length) {
        let spec = [res.object[0].goodsSpecs[0]]
        let arr=[]
        res.object[0].goodsSpecs.forEach(function(v,index){
          if(index!=0){
            arr.push(v)
          }
        })
        spec[0]['goodsSpecs']=arr
        that.setData({
          spec
        })
      }
    })
    //新客专区
    api.rookieGoods({
      cityId: wx.getStorageSync("cityId"),
      userId: wx.getStorageSync("openId"),
    }).then(res=>{
      if (res.result){
        if(wx.getStorageSync('type') == "2"){
          res.object.forEach(v=>{
            api.roleSwitch(v.goodsDetailsEntityList[0])
          })
        }
        that.setData({
          rookieGoods:res.object
        })
      }
    })
    //vip专区
    api.vipGoods({
      cityId: wx.getStorageSync("cityId"),
      userId: wx.getStorageSync("openId"),
    }).then(res => {
      if (res.result) {
        if(wx.getStorageSync('type') == "2"){
          res.object.forEach(v=>{
            api.roleSwitch(v.goodsDetailsEntityList[0])
          })
        }
        that.setData({
          vipGoods: res.object
        })
      }
    })
  },
  kill(){
    let that = this
     //秒杀专场
     api.seckill({
      cityId: wx.getStorageSync("cityId"),
      userId: wx.getStorageSync("openId"),
    }).then(res=>{
      if (res.result && (res.object && res.object.length > 0)){
        let begin = res.object[0].goodsDetailsEntityList[0].seckillBeginDate
        let end = res.object[0].goodsDetailsEntityList[0].seckillEndDate
        if (begin > Date.now()){
          let now = begin - Date.now()
          console.log(now)
          that.startTimer(begin)
          that.setData({
            showBegin:true
          })
          setTimeout(function () {
            that.startTimer(end)
            that.setData({
              showBegin: false
            })
          }, now)
        }else{
          that.startTimer(end)
          
        }
        that.setData({
          limited_list: res.object,
        })
      }
    })
  },
  // 倒计时
  startTimer(end) {
    let that=this
    let now = Date.now()
    let hour = time.formatTimeTwo(end - now, 'h') - 8 + (time.formatTimeTwo(end - now, 'D') - 1) * 24
    that.setData({
      hour,
      minute: time.formatTimeTwo(end - now, 'm'),
      second: time.formatTimeTwo(end - now, 's'),
    })
     var timer = setInterval(() => {
      let now = Date.now()
      let hour = time.formatTimeTwo(end - now, 'h') - 8 + (time.formatTimeTwo(end - now, 'D') - 1) * 24
      that.setData({
        hour,
        minute: time.formatTimeTwo(end - now, 'm'),
        second: time.formatTimeTwo(end - now, 's'),
      })
      if ((end - Date.now()) < 1000) {
        clearInterval(timer)
        timer = null
        that.setData({
          onOff:false,
          hour:'00',
          minute: '00',
          second: '00',
        })
      }
    }, 1000)
  },
  btnStop(e){
    let that = this
    let item = e.currentTarget.dataset.item//数组
    let begin = item.seckillBeginDate
    let end = item.seckillEndDate
    let now = Date.now()
    if (begin <= now && end >= now){
      let limited_list = that.data.limited_list
      let index = e.currentTarget.dataset.index//数组下标
      let startNum = +item.startNum//起送数量
      let amount = item.amount;//购物车内商品数量
      if (amount == 0) {
        amount = startNum //购物车商品数量加
      } else {
        amount = amount + 1
      }
      // 访问接口更新数据
      // TODO 获取userId/cityId
      let userInfoId = wx.getStorageSync("openId")//用户ID
      let cityId = wx.getStorageSync("cityId")//城市ID
      let goodsName = e.currentTarget.dataset.name//商品名
      let goodsDetailsId = item.id//商品id
      let totalPrice = item.seckillPrice * amount + ''//总价
      let price = item.seckillPrice//商品价格
      //购物车接口
      api.goodsNumber({
        cityId,
        userInfoId,
        goodsName,
        goodsDetailsId,
        amount,
        price,
        totalPrice
      }).then(res => {
        if (res.result) {
          if (res.data > 0) {
            wx.setTabBarBadge({
              index: 3,
              text: res.data //显示的内容 
            })
          } else {
            wx.hideTabBarRedDot({
              index: 3
            })
          }
          wx.showToast({
            title: "添加成功",
            icon: 'none'
          })
          limited_list[index].goodsDetailsEntityList[0].amount = amount
          that.setData({
            limited_list
          })
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    } else if (begin >= now){
      wx.showToast({
        title: '秒杀还未开始',
        icon: 'none',
        duration: 1000
      })
    }else{
      wx.showToast({
        title: '秒杀已经结束',
        icon: 'none',
        duration: 1000
      })
    }
    

  } ,
  getRatio: function() {
    //根据分类获取比例
    var self = this;
    if (self.data.firstList.length <= 4) {
      this.setData({
        slideShow: false
      })
    } else {
      //分类列表总长度
      var _totalLength = self.data.arr.length * 90;
      //滚动列表长度与滑条长度比例
      var _ratio = 200 / _totalLength * (750 / this.data.windowWidth);
      //当前显示红色滑条的长度(保留两位小数)
      var _showLength = 750 / _totalLength * 200;
  
      this.setData({
        slideWidth: _showLength,
        totalLength: _totalLength,
        slideShow: true,
        slideRatio: _ratio
      })
    }
  },
  //slideLeft动态变化
  getleft: function(e) {
    this.setData({
      slideLeft: e.detail.scrollLeft * this.data.slideRatio
    })
  },
  // 点击导航更换商品大类
  switchTap: function(e) {
    // 全屏宽度
    let screenWidth = wx.getSystemInfoSync().windowWidth;
    // 每个导航项宽度
    let itemWidth = screenWidth / 4;
    // 获取到当前被点击的导航项的索引index type.
    const {nav_list} = this.data;
    // 当前选项样式
    let type_id = e.currentTarget.dataset.id
    let index = e.currentTarget.dataset.index
    // 计算出当它居中时横向滚动框应该滚动的距离
    // itemWidth*index是滚动到最左侧的距离，再减去itemWidth*2就刚好等于了滑动到中间的距离.
    let scrollX = itemWidth * index;
    // 所有的导航项的宽度的总和
    let maxScrollX = (nav_list.length + 1) * itemWidth;
    // 这个滚动的距离既不能小于0,也不能比最大的长度还长(这个最大的长度就是所有的导航项的宽度的总和).
    if (scrollX < 0) {
      scrollX = 0;
    } else if (scrollX >= maxScrollX) {
      scrollX = maxScrollX;
    }
    // 然后赋值给x让滚动条滚动.
    this.setData({
      x: scrollX,
      type_id: type_id
    })
    this.navGoodsList()
  },
  // 跳转到选择城市
  tocity: common.throttleFunc(function (e) {
    wx.navigateTo({
      url: '/pages/city/city?cityId=' + e.currentTarget.dataset.city,
    })
  }),
  // 滚动事件,导航固定
  onPageScroll: function(e) {
    var that = this;
    let query = wx.createSelectorQuery()
    query.select("#scroll").boundingClientRect((rect) => {
      
      // 动态获取#scroll距离顶部的距离
      let top = rect.top
      if (top <= 0) {
        that.setData({
          fixedNav: 'fixed'
        })
      } else {
        that.setData({
          fixedNav: ''
        })
      }
    }).exec();
  },
  //腾讯地图key
  city() {
    qqmapsdk = new QQMapWX({
      key: 'JB3BZ-OLZCG-NSTQ2-IY7AB-LXSG2-SUFZN'
    });

  },

  //获取当前位置 允许 拒绝
  getUserLocation: function () {
    
    let vm = this;
    wx.getSetting({
      success: (res) => {
        
        if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
          wx.showModal({
            title: '请求授权当前位置',
            content: '需要获取您的地理位置，请确认授权',
            success: function (res) {
              if (res.cancel) {
                wx.showToast({
                  title: '拒绝授权',
                  icon: 'none',
                  duration: 1000
                })
                
                vm.getLocation();

                
              
              } else if (res.confirm) {
                wx.openSetting({
                  success: function (dataAu) {
                    
                    if (dataAu.authSetting["scope.userLocation"] == true) {
                      
                      wx.showToast({
                        title: '授权成功',
                        icon: 'success',
                        duration: 1000
                      })

                      //再次授权，调用wx.getLocation的API
                      vm.getLocation();
                    } else {
                      wx.showToast({
                        title: '授权失败',
                        icon: 'none',
                        duration: 1000
                      })
                      vm.setData({
                        city: '长春'
                      })
                      vm.getLocation();
                
                    }
                  }
                })
              }
            }
          })
        } else if (res.authSetting['scope.userLocation'] == undefined) {
          //调用wx.getLocation的API
          vm.getLocation();
        }
        else {
          //调用wx.getLocation的API
          vm.getLocation();
        }
      }
    })
  },
  // 微信获得经纬度
  getLocation: function () {
    let vm = this;
   
    wx.getLocation({
      type: 'gcj02',
      success:  function (res) {

        var latitude = res.latitude
        var longitude = res.longitude
        var speed = res.speed
        var accuracy = res.accuracy;
        
        vm.getLocal(latitude, longitude)
      },
      fail:async function (res) {
        vm.setData({
          city: '长春市'
        })
       await wx.setStorageSync("cityId", "a2be5cc2bc87d1fbe0501aacc1795bbf")
        vm.getAll()
      }
    })
  },
  getAll(){
    let that=this
      that.navGoodsList()
      that.getIndexSpc()
    // 轮播图和公告
    api.bannerList({
      cityId: wx.getStorageSync("cityId")
    }).then(res => {
      if (res.result) {
        var arr=[]
        //遍历数组下面的url是否为null
        res.object.forEach(function(v){
            if(v.url!=null){
              arr.push(v)
            }
        })
        that.setData({
          imgUrls: arr
        })
      }
    })
    //公告
    api.noticeList({
    }).then(res => {
      if (res.result) {
        that.setData({
          noticeList: res.object
        })
      }
    })
    if (that.data.nav_list.length == 1) {
      that.navList()
    }  },
  // 获取当前地理位置
  getLocal: function (latitude, longitude) {
    let vm = this;
    
    qqmapsdk.reverseGeocoder({
      location: {
        latitude: latitude,
        longitude: longitude
      },
      success: function (res) {
        api.cityId({
          name: res.result.ad_info.city
        }).then(res => {
          if (res.result) {
            wx.setStorageSync("cityId", res.object.id)
            let that = vm
            that.setData({
              cityId: res.object.id
            })
            that.getAll()
          }
        })
        let province = res.result.ad_info.province
        let city = res.result.ad_info.city
        //小程序本地储存
        vm.setData({
          province: province,
          city: city,
          latitude: latitude,
          longitude: longitude
        })
        
      },
      // 首页自动获取地址
      fail: function (res) {
        api.cityId({
          name: vm.data.city
        }).then(res => {
        
          if (res.result) {
            wx.setStorageSync("cityId", res.object.id)
            vm.setData({
              // city: '长春',
              cityId: res.object.id
            })
          }
        })
        
      },
      complete: function (res) {

      }
    });
   
  },
  getShopSum() {
    api.get_cart({
      cityId: wx.getStorageSync("cityId"),
      userId: wx.getStorageSync("openId"),
      page: {}
    })
      .then(res => {
        let getSum = res.data.body.getSum;
        if (getSum > 0) {
          wx.setTabBarBadge({
            index: 3,
            text: getSum + '' //显示的内容 
          })
        } else {
          wx.hideTabBarRedDot({
            index: 3
          })
        }
      })
  },
  onShow: function (options){
    let that=this
    that.setData({
      login: wx.getStorageSync('token') ? wx.getStorageSync('codeNum')==99?true:false: false,
      loginCode: wx.getStorageSync('codeNum') == 103 ? true :  wx.getStorageSync('codeNum')==105?true:false,
      loginCode1: wx.getStorageSync('codeNum') == 104 ? true :false,
      vipId: wx.getStorageSync('vipFlag')
    })
    //判断登录
    if(that.data.login){
      that.getShopSum()
    }
    //公告onshow
    that.navGoodsList()
    
   },
   //获取商品数据
  getGoodsList(){
    let that=this
    let currents = that.data.currents
    // 再次调用
    api.goodsList({
      cityId: wx.getStorageSync('cityId'),
      userId: wx.getStorageSync("openId"),
      typeId: that.data.type_id,
      page: {
        startPage: false,//是否开启上滑加载
        size: that.data.size,//请求数据 渲染几条
        current: currents,//当前页
      }
    }).then(res => {
      that.data.totalPage= res.object.pages//获取总页数
      if (res.result) {
        if(wx.getStorageSync('type') == "2"){
          res.object.records.forEach(v=>{
            api.roleSwitch(v.goodsDetailsEntityList[0])
          })
        }
      this.kill()
      res.object.records.forEach(v=>{
        let num = v.goodsDetailsEntityList[0].stockAmount/v.goodsDetailsEntityList[0].spec
        v.goodsDetailsEntityList[0].stockAmount = Math.floor(num)
      })
        that.setData({
          proList: [...that.data.proList, ...res.object.records],
          // proList: this.data.proList.concat(res.object.records),
          currents: currents
        })
      }

    })
    
    
  },
  navGoodsList: function (e)  {
    if(off){
      off = false
      return
    }
    let that = this
    let currents = that.data.currents
    that.setData({
      currents: 1,
      // 数据是否加载完
      noMore: false,
      // 加载中
      loading: false,
    })
    // 再次调用
    api.goodsList({
      cityId: wx.getStorageSync('cityId'),
      userId: wx.getStorageSync("openId"),
      typeId: that.data.type_id,
      page: {
        startPage: false,//是否开启上滑加载
        size: that.data.size,//请求数据 渲染几条
        current: 1,//当前页
      }
    }).then(res => {
      that.data.totalPage = res.object.pages//获取总页数
      if (res.result) {
        let vip = (res.object.records[0] && res.object.records[0].userInfoEntity.vipFlag) || null
        if(vip=='0'||vip=='1'){
          wx.setStorageSync('vipFlag', vip)
        }
        if(wx.getStorageSync('type') == "2"){
          res.object.records.forEach(v=>{
            api.roleSwitch(v.goodsDetailsEntityList[0])
          })
        }
        res.object.records.forEach(v=>{
          let num = v.goodsDetailsEntityList[0].stockAmount/v.goodsDetailsEntityList[0].spec
          v.goodsDetailsEntityList[0].stockAmount = Math.floor(num)
        })
        that.setData({
          proList:  res.object.records,
          currents: 1
        })
      }
    })
    setTimeout(function () {
      that.setData({
        // 数据是否加载完
        noMore: false,
        // 加载中
        loading: false,
      })
    }, 1000)

  },
  navList(){
    let that=this
    api.navList({
      cityId:wx.getStorageSync("cityId")
    }).then(res => {
      if (res.result) {
        that.setData({
          nav_list: that.data.nav_list.concat(res.object),
        })
      }

    })
    api.getDefault({
      cityId: wx.getStorageSync('cityId'),
    }).then(res => {

      if (res.result) {
        that.setData({
          getDefault: res.object
        })

      }

    })
  },
  // 上滑加载 
  onReachBottom(){
    let that=this
    if (that.data.currents >= that.data.totalPage){
      that.setData({
        noMore: true,
        loading: false,
      })
    }else{
      let currents = that.data.currents
      let size = that.data.size
      that.setData({
        noMore: false,
        loading: true,
        currents: 1,
      })
      
      size = size + 10
      // 再次调用
      api.goodsList({
        cityId: wx.getStorageSync('cityId'),
        userId: wx.getStorageSync("openId"),
        typeId: that.data.type_id,
        page: {
          startPage: false,//是否开启上滑加载
          size: size,//请求数据 渲染几条
          current: 1,//当前页
        }
      }).then(res => {
        that.data.totalPage = res.object.pages//获取总页数
        if(wx.getStorageSync('type') == "2"){
          res.object.records.forEach(v=>{
            api.roleSwitch(v.goodsDetailsEntityList[0])
          })
        }
        if (res.result) {
          that.setData({
            proList: res.object.records,
            currents: 1,
            size
          })
        }
      })
      setTimeout(function () {
        that.setData({
          noMore: false,
          loading: false,
        })
      }, 1000)
    }
  },
  //下拉刷新
  onPullDownRefresh() {
    //重置数组
    this.setData({
      proList: [],
      currents:1,
      size:10,
      // 数据是否加载完
      noMore: false,
      // 加载中
      loading: false,

    })
    //总页数恢复默认
    //重新发送请求
    this.getGoodsList()
    this.getIndexSpc()
    //关闭下拉刷新
    wx.stopPullDownRefresh()
  },
  //搜索跳转
  handleSearch() {
    wx.navigateTo({
      url: '/pages/search_index/search_index',
    })
  },
  onShareAppMessage() {
    return {
      title: '京天鲜生, 生鲜管家',
      path: '/pages/index/index',
      imageUrl: '../../images/share.jpeg', // 可以更换分享的图片
    }
  },
  //专区跳转
  toSpec: common.throttleFunc(function (e) {
    let connType = e.currentTarget.dataset.conntype
    let connAddr = e.currentTarget.dataset.connaddr
    if (connType == 1) {//分类
      wx.setStorageSync("navId", connAddr)
      wx.switchTab({
        url: '/pages/fenlei/fenlei'
      })
    } else {//小程序 h5
      wx.navigateTo({
        url: strDiscode(e.currentTarget.dataset.connaddr),
      })
    }
  }),
  //banner跳转
  swiperDetail: common.throttleFunc(function (e) {
    let connType = e.currentTarget.dataset.conntype
    if (wx.getStorageSync("type") == -1) {
      wx.showToast({
        title: '请您先进行身份选择',
        icon: 'none',
        duration: 1500
      })
      wx.navigateTo({
        url: '/pages/sf_xz/sf_xz',
      })
    } else if (wx.getStorageSync("type") == 1) {
      if (wx.getStorageSync('codeNum') == 103) {
        //未注册商铺 跳转商铺注册页
        wx.showToast({
          title: '您还未注册店铺！',
          icon: 'none',
          duration: 1500
        })

        wx.navigateTo({
          url: '/pages/type/type',
        })


      } else if (wx.getStorageSync('codeNum') == 104) {
        //商铺审核中 
        wx.showToast({
          title: '您的商铺审核中！',
          icon: 'none',
          duration: 1000
        })

        wx.navigateTo({
          url: '/pages/shopBack/shopBack?type=' + 1,
        })



      }
      else if (wx.getStorageSync('codeNum') == 105) {
        //商铺审核未通过
        wx.showToast({
          title: '您申请的店铺暂未审核通过！',
          icon: 'none',
          duration: 1000
        })

        wx.navigateTo({
          url: '/pages/type/type',
        })


      }
      else if (wx.getStorageSync('codeNum') == 99) {

        if (connType == 1) {//分类
          wx.setStorageSync("navId", id)
          wx.switchTab({
            url: '/pages/fenlei/fenlei'
          })
        } else {//h5 小程序
          wx.navigateTo({
            url: e.currentTarget.dataset.url,
          })
        }
      }

    } else if (wx.getStorageSync("type") == 2) {
      if (wx.getStorageSync('codeNum') != 99) {
        wx.showToast({
          title: '请您先注册一个收货地址',
          icon: 'none',
          duration: 1500
        })
        wx.navigateTo({
          url: '/pages/edit-address/edit-address',
        })
      } else {
        if (connType == 1) {//分类
          wx.setStorageSync("navId", id)
          wx.switchTab({
            url: '/pages/fenlei/fenlei'
          })
        } else {//h5 小程序
          wx.navigateTo({
            url: e.currentTarget.dataset.url,
          })
        }
      }

    } else if (wx.getStorageSync('codeNum') == 99) {

      if (connType == 1) {//分类
        wx.setStorageSync("navId", id)
        wx.switchTab({
          url: '/pages/fenlei/fenlei'
        })
      } else {//h5 小程序
        wx.navigateTo({
          url: e.currentTarget.dataset.url,
        })
      }
    }else {
      wx.navigateTo({
        url: '/pages/userMess/userMess',
      })
    }
   
  }),
  //icon跳转
  handleNavs(e) {
    let typeid = e.detail.e.currentTarget.dataset.typeid;
    let type = e.detail.e.currentTarget.dataset.type;
    let connaddr = e.detail.e.currentTarget.dataset.connaddr;
    if (wx.getStorageSync("type") == -1) {
      wx.showToast({
        title: '请您先进行身份选择',
        icon: 'none',
        duration: 1500
      })
      wx.navigateTo({
        url: '/pages/sf_xz/sf_xz',
      })
    } else if (wx.getStorageSync("type") == 1 ) {
      if (wx.getStorageSync('codeNum') == 103) {
        //未注册商铺 跳转商铺注册页
        wx.showToast({
          title: '您还未注册店铺！',
          icon: 'none',
          duration: 1500
        })

        wx.navigateTo({
          url: '/pages/type/type',
        })


      } else if (wx.getStorageSync('codeNum') == 104) {
        //商铺审核中 
        wx.showToast({
          title: '您的商铺审核中！',
          icon: 'none',
          duration: 1000
        })

        wx.navigateTo({
          url: '/pages/shopBack/shopBack?type=' + 1,
        })



      }
      else if (wx.getStorageSync('codeNum') == 105) {
        //商铺审核未通过
        wx.showToast({
          title: '您申请的店铺暂未审核通过！',
          icon: 'none',
          duration: 1000
        })

        wx.navigateTo({
          url: '/pages/type/type',
        })


      }
      else if (wx.getStorageSync('codeNum') == 99) {
        
        if (type == 1) {//分类
          wx.setStorageSync("navId", typeid)
          wx.switchTab({
            url: '/pages/fenlei/fenlei'
          })
        } else {//小程序  h5
          wx.navigateTo({
            url: connaddr,
          })
        }
      }

    } else if (wx.getStorageSync("type") == 2) {
      if (wx.getStorageSync('codeNum') != 99) {
        wx.showToast({
          title: '请您先注册一个收货地址',
          icon: 'none',
          duration: 1500
        })
        wx.navigateTo({
          url: '/pages/edit-address/edit-address',
        })
      } else {
        let typeid = e.detail.e.currentTarget.dataset.typeid;
        let type = e.detail.e.currentTarget.dataset.type;
        let connaddr = e.detail.e.currentTarget.dataset.connaddr;
        if (type == 1) {//分类
          wx.setStorageSync("navId", typeid)
          wx.switchTab({
            url: '/pages/fenlei/fenlei'
          })
        } else {//小程序  h5
          wx.navigateTo({
            url: e.currentTarget.dataset.connaddr,
          })
        }
      }

    } else if (wx.getStorageSync('codeNum') == 99) {
      let typeid = e.detail.e.currentTarget.dataset.typeid;
      let type = e.detail.e.currentTarget.dataset.type;
      let connaddr = e.detail.e.currentTarget.dataset.connaddr;
      if (type == 1) {//分类
        wx.setStorageSync("navId", typeid)
        wx.switchTab({
          url: '/pages/fenlei/fenlei'
        })
      } else {//小程序  h5
        wx.navigateTo({
          url: e.currentTarget.dataset.connaddr,
        })
      }
    }else {
      wx.navigateTo({
        url: '/pages/userMess/userMess',
      })
    }
    
    
  }
  
})